//
//  SelecedViewController.m
//  FKGW
//
//  Created by song ce on 2017/2/15.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "SelecedViewController.h"
#import "SvGifView.h"
#import "TabBarControllerCongig.h"
#import "AppDelegate.h"
#import "UIView+Extend.h"
#import "LivingViewController.h"

@interface SelecedViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UIButton *liveButton;
@property (weak, nonatomic) IBOutlet UIButton *buyButton;
@property (weak, nonatomic) IBOutlet UIImageView *shuidiImageV;
@property (weak, nonatomic) IBOutlet UIImageView *shopImageV;
@property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;

@property (weak, nonatomic) IBOutlet UIImageView *shuidimageV;
@property(nonatomic,assign)BOOL  flag;

@property(nonatomic,strong)SvGifView *gifView;

//@property(nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation SelecedViewController
-(instancetype)init{
    self = [super init];
    if(self){
        //监听子视图滑动情况
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gifDidStop) name:@"gifDidStop" object:nil];
         }
    return self;
}

- (void)gifDidStop{
    self.shuidiImageV.hidden = NO;
    self.welcomeLabel.hidden = NO;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.vcName = @"疯狂购物城";
    //  设置字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor colorWithRed:255./255 green:215./255 blue:0./255 alpha:1], NSForegroundColorAttributeName, [UIFont boldSystemFontOfSize:18], NSFontAttributeName, nil]];
     // 设置水滴gif
    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"水滴-kuo" withExtension:@"gif"];
    
    CGFloat  shopTop= self.shopImageV.top;
    CGFloat  shuidiBottom = self.shuidiImageV.bottom;
    CGFloat distance =shuidiBottom-shopTop+10;
    CGFloat  x =Main_Screen_Width/2+distance/2*.96;
    if(Main_Screen_Width==414){
        x =Main_Screen_Width/2+distance/2*.50;
    }
     _gifView = [[SvGifView alloc] initWithFrame:CGRectMake(x, shopTop, distance*.65, distance) fileURL:fileUrl];
    _gifView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    [self.view insertSubview:_gifView aboveSubview:_bgImageView];
    
//    [self testData];
}



- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.flag=YES;
    [self performSelector: @selector(start_GIf) withObject:nil afterDelay:1.6];
     [self hiddenAndShow];
}

- (void)start_GIf{
          [_gifView startGif];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    self.flag=NO;
    [self hiddenAndShow];
}

//  看直播
- (IBAction)live:(UIButton *)sender {
//    [MBProgressHUD showTipMessageInWindow:@"该功能正在开发\r\n敬请期待..."];
        LivingViewController *livingViewController = [[LivingViewController alloc]init];
        BaseNavigationViewController *navi = [[BaseNavigationViewController alloc]initWithRootViewController:livingViewController];
       [[AppDelegate appDealegate].window setRootViewController: navi];
}
- (IBAction)buy:(UIButton *)sender {
    TabBarControllerCongig *tabBarControllerConfig = [[TabBarControllerCongig alloc] init];
    SelectedConditionViewController *right = [[SelectedConditionViewController alloc]init];
    self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:tabBarControllerConfig.tabBarController leftDrawerViewController:nil rightDrawerViewController:right];
    [[AppDelegate appDealegate].window setRootViewController: self.drawerController];
    //设置右滑得距离
    [self.drawerController setMaximumRightDrawerWidth:Main_Screen_Width/4*3];
    //    [self.drawerController setMaximumLeftDrawerWidth:80.0];
    //设置打开的手势的作用范围
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    //设置关闭的手势的作用范围
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];    //设置打开左右侧滑界面的样式
    
//    self.drawerController.showsStatusBarBackgroundView = YES;
//    self.drawerController.statusBarViewBackgroundColor = [UIColor blackColor];
    [self.drawerController
     setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
         MMDrawerControllerDrawerVisualStateBlock block;
         //提供滑动的样式的单例（这个类并没有加在框架内，使用的时候直接将文件加入框架内就可以）
         block = [[MMExampleDrawerVisualStateManager sharedManager]
                  drawerVisualStateBlockForDrawerSide:drawerSide];
         if(block){
             block(drawerController, drawerSide, percentVisible);
             
         }
     }];
   }

//下面按钮的动画
- (void)hiddenAndShow{
    [UIView animateWithDuration:1 animations:^{
        if(self.liveButton.alpha==1){
            self.liveButton.alpha = 0;
            self.buyButton.alpha =0;
        }else{
            self.liveButton.alpha = 1;
           self.buyButton.alpha = 1;
        }
    }];
    if(self.flag==YES){
        [self performSelector:@selector(hiddenAndShow) withObject:nil afterDelay:1];
//        DLog(@"正在执行hiddenandshow");
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
